package jmars.mobile.domain;

import java.text.DecimalFormat;

public class NumericalFeature {
	private Double min;
	private Double max;
	private Double sum;
	private Integer count;
	private Double avg;
	private Double med;
	private Double uQuart;
	private Double lQuart;
	DecimalFormat df = new DecimalFormat();
	
	public NumericalFeature(){
		df.applyPattern("0,000.000");
	}
	
	@Override
	public String toString(){
		StringBuffer sb =new StringBuffer();
		if(count!=null)sb.append("count:"+count+". ");
		if(sum!=null)sb.append("sum:"+df.format(sum)+". ");
		if(min!=null)sb.append("min:"+df.format(min)+". ");
		if(max!=null)sb.append("max:"+df.format(max)+". ");
		if(avg!=null)sb.append("avg:"+df.format(avg)+". ");
		if(med!=null)sb.append("med:"+med+". ");
		if(lQuart!=null)sb.append("lQuart:"+lQuart+". ");
		if(uQuart!=null)sb.append("uQuart:"+uQuart+". ");
		return sb.toString();
	}
	
	public void update(Double item){
		if(avg==null)setAvg(0D);
		if(count==null)setCount(0);
		if(sum==null)setSum(0D);
		this.setCount(this.getCount()+1);
		this.setSum(this.getSum()+item);
		if(null==this.getMin()||this.getMin()>item)this.setMin(item);
		if(null==this.getMax()||this.getMax()<item)this.setMax(item);
		this.setAvg(this.getSum()/this.getCount());
		if(this.getMin()>item)this.setMin(item);
		
	}
	
	public Double getMin() {
		return min;
	}
	public void setMin(Double min) {
		this.min = min;
	}
	public Double getMax() {
		return max;
	}
	public void setMax(Double max) {
		this.max = max;
	}
	public Double getSum() {
		return sum;
	}
	public void setSum(Double sum) {
		this.sum = sum;
	}
	public Integer getCount() {
		return count;
	}
	public void setCount(Integer count) {
		this.count = count;
	}
	public Double getAvg() {
		return avg;
	}
	public void setAvg(Double avg) {
		this.avg = avg;
	}
	public Double getMed() {
		return med;
	}
	public void setMed(Double med) {
		this.med = med;
	}
	public Double getuQuart() {
		return uQuart;
	}
	public void setuQuart(Double uQuart) {
		this.uQuart = uQuart;
	}
	public Double getlQuart() {
		return lQuart;
	}
	public void setlQuart(Double lQuart) {
		this.lQuart = lQuart;
	}
}
